package com.mathassistant.server.domain;

import java.util.ArrayList;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.mathassistant.shared.TopicDTO;


@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Topic {
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
	private String key;
	
	@Persistent
	private
	String content;
	
	@Persistent(mappedBy = "topicExercise")
    private ArrayList<Exercise> exercises = new ArrayList<Exercise>();
	
	@Persistent(mappedBy = "topicTheory")
	 private ArrayList<Theory> theorys = new ArrayList<Theory>();
	
	@Persistent(mappedBy = "topicExamination")
	private FinalTest exam;
	
	@Persistent
	private String area;
	
	@Persistent
	private String contentType;
	
	public Topic(){
	}
	public Topic(String content, String area, String contentType)
	{
		this.setContent(content);
		this.setArea(area);
		this.setContentType(contentType);
	}
	public Topic(TopicDTO topicDTO)
	{
		this.setContent(topicDTO.getContent());
		this.setArea(topicDTO.getArea());
		this.setContentType(topicDTO.getContentType());
	}
	
	public String getKey()
	{
		return key;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getContent() {
		return content;
	}
	
	public void setExercises(ArrayList<Exercise> exercises) {
		this.exercises = exercises;
	}
	public ArrayList<Exercise> getExercises() {
		return exercises;
	}
	public TopicDTO toDTO(){
		return new TopicDTO(this.getKey(), this.getContent(),this.getArea(),this.getContentType());
	}
	public void updateFromDTO(TopicDTO topicDTO){
		this.setContent(topicDTO.getContent());
	}
	public void setArea(String area) {
		this.area = area;
	}
	public String getArea() {
		return area;
	}
	public void setContentType(String contentType) {
		this.contentType = contentType;
	}
	public String getContentType() {
		return contentType;
	}
	public void setTheorys(ArrayList<Theory> theorys) {
		this.theorys = theorys;
	}
	public ArrayList<Theory> getTheorys() {
		return theorys;
	}
	public void setExam(FinalTest exam) {
		this.exam = exam;
	}
	public FinalTest getExam() {
		return exam;
	}
}
